﻿using CoreWeb.Models;
using Microsoft.AspNetCore.Mvc;

namespace CoreWeb.Controllers
{
    public class FirstController : Controller
    {
        private readonly ILogger<FirstController> _logger;

        public FirstController(ILogger<FirstController> logger)
        {
            _logger = logger;
        }

        public IActionResult Index()
        {
            _logger.LogInformation("123");
            #region ViewData
            base.ViewData["User1"] = new CurrentUser()
            {
                Id = 7,
                Name = "Y",
                Account = "花心大萝卜",
                Email = "莲花未开时",
                Password = "落单的候鸟",
                LoginTime = DateTime.Now
            };

            ViewData["Something"] = 12345;
            #endregion
            #region ViewBag
            ViewBag.Name = "Eleven";
            ViewBag.Description = "Teacher";
            ViewBag.User = new CurrentUser()
            {
                Id = 7,
                Name = "CSS",
                Account = "季雨林",
                Email = "Koke",
                Password = "落单的候鸟",
                LoginTime = DateTime.Now
            };
            #endregion
            #region TempData

            TempData["User"] = new CurrentUser()
            {
                Id = 7,
                Name = "CSS",
                Account = "季雨林",
                Email = "Koke",
                Password = "落单的候鸟",
                LoginTime = DateTime.Now
            };
            #endregion
            #region Session
            if (string.IsNullOrWhiteSpace(this.HttpContext.Session.GetString("CurrentUserSession")))
            {
                base.HttpContext.Session.SetString("CurrentUserSession", Newtonsoft.Json.JsonConvert.SerializeObject(
                    new CurrentUser()
                    {
                        Id = 7,
                        Name = "一点半",
                        Account = "季雨林",
                        Email = "Koke",
                        Password = "落单的候鸟",
                        LoginTime = DateTime.Now
                    }));
            }
            #endregion
            #region Model
            return View(new CurrentUser()
            {
                Id = 7,
                Name = "一点半",
                Account = "季雨林",
                Email = "Koke",
                Password = "落单的候鸟",
                LoginTime = DateTime.Now
            });
            #endregion 
        }
    }
}
